package com.ruoyi.web.controller.workJob;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.worker.domain.RzAttendancePassRecord;
import com.ruoyi.worker.service.IRzAttendancePassRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 描述:考勤机打卡通行记录
 *
 * @author 刘松山
 * @date 2022/1/17 14:33
 */
@RestController
@RequestMapping("/traffic/record")
public class RzAttendancePassRecordController extends BaseController {
    @Autowired
    private IRzAttendancePassRecordService rzAttendancePassRecordService;

    /**
     * 查询长期工通行记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(RzAttendancePassRecord rzAttendancePassRecord) {
        startPage();
        List<RzAttendancePassRecord> list = rzAttendancePassRecordService.selectRzAttendancePassRecordList(rzAttendancePassRecord);
        return getDataTable(list);
    }

    /**
     * 导出长期工通行记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "长期工通行记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RzAttendancePassRecord rzAttendancePassRecord) {
        List<RzAttendancePassRecord> list = rzAttendancePassRecordService.selectRzAttendancePassRecordList(rzAttendancePassRecord);
        ExcelUtil<RzAttendancePassRecord> util = new ExcelUtil<RzAttendancePassRecord>(RzAttendancePassRecord.class);
        return util.exportExcel(list, "长期工通行记录数据");
    }

    /**
     * 获取长期工通行记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{staffName}")
    public AjaxResult getInfo(@PathVariable("staffName") String staffName) {
        return AjaxResult.success(rzAttendancePassRecordService.selectRzAttendancePassRecordByStaffName(staffName));
    }

    /**
     * 新增长期工通行记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "长期工通行记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RzAttendancePassRecord rzAttendancePassRecord) {
        return toAjax(rzAttendancePassRecordService.insertRzAttendancePassRecord(rzAttendancePassRecord));
    }

    /**
     * 修改长期工通行记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "长期工通行记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RzAttendancePassRecord rzAttendancePassRecord) {
        return toAjax(rzAttendancePassRecordService.updateRzAttendancePassRecord(rzAttendancePassRecord));
    }

    /**
     * 删除长期工通行记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "长期工通行记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{staffNames}")
    public AjaxResult remove(@PathVariable String[] staffNames) {
        return toAjax(rzAttendancePassRecordService.deleteRzAttendancePassRecordByStaffNames(staffNames));
    }

}
